package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.vo.SysAssetScrapVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.SysAssetScrap;
import com.ruoyi.system.service.ISysAssetScrapService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 资产报废申请Controller
 * 
 * @author sxy
 * @date 2025-04-02
 */
@RestController
@RequestMapping("/scrap")
public class SysAssetScrapController extends BaseController
{
    @Autowired
    private ISysAssetScrapService sysAssetScrapService;

    /**
     * 查询资产报废申请列表
     */
    @RequiresPermissions("system:scrap:list")
    @GetMapping("/list")
    public TableDataInfo list(SysAssetScrap sysAssetScrap)
    {
        startPage();
        List<SysAssetScrapVo> list = sysAssetScrapService.selectSysAssetScrapList(sysAssetScrap);
        return getDataTable(list);
    }

    /**
     * 导出资产报废申请列表
     */
    @RequiresPermissions("system:scrap:export")
    @Log(title = "资产报废申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysAssetScrap sysAssetScrap)
    {
        List<SysAssetScrapVo> list = sysAssetScrapService.selectSysAssetScrapList(sysAssetScrap);
        ExcelUtil<SysAssetScrapVo> util = new ExcelUtil<SysAssetScrapVo>(SysAssetScrapVo.class);
        util.exportExcel(response, list, "资产报废申请数据");
    }

    /**
     * 获取资产报废申请详细信息
     */
    @RequiresPermissions("system:scrap:query")
    @GetMapping(value = "/{scrapId}")
    public AjaxResult getInfo(@PathVariable("scrapId") Long scrapId)
    {
        return success(sysAssetScrapService.selectSysAssetScrapByScrapId(scrapId));
    }

    /**
     * 新增资产报废申请
     */
    @RequiresPermissions("system:scrap:add")
    @Log(title = "资产报废申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysAssetScrap sysAssetScrap)
    {
        return toAjax(sysAssetScrapService.insertSysAssetScrap(sysAssetScrap));
    }

    /**
     * 修改资产报废申请
     */
    @RequiresPermissions("system:scrap:edit")
    @Log(title = "资产报废申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysAssetScrap sysAssetScrap)
    {
        return toAjax(sysAssetScrapService.updateSysAssetScrap(sysAssetScrap));
    }

    /**
     * 删除资产报废申请
     */
    @RequiresPermissions("system:scrap:remove")
    @Log(title = "资产报废申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{scrapIds}")
    public AjaxResult remove(@PathVariable Long[] scrapIds)
    {
        return toAjax(sysAssetScrapService.deleteSysAssetScrapByScrapIds(scrapIds));
    }
}
